import { login } from '@/api/user'
const state = {
  token: localStorage.getItem('token') || ''
}
const mutations = {
  setToken(state, data) {
    state.token = data
    localStorage.setItem('token', data)
  }
}
const actions = {
  async login({ commit }, data) {
    const { jwt } = await login(data)
    commit('setToken', jwt)
  }
}

export default {
  state,
  mutations,
  actions,
  namespaced: true
}
